/**
 * Copyright 2025 Adobe. All rights reserved.
 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License. You may obtain a copy
 * of the License at http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under
 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
 * OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */

@import url("./spectrum-textfield.css");
@import url("./textfield-overrides.css");

:host {
    display: inline-flex;
    flex-direction: column;
    inline-size: var(--mod-textfield-width, var(--spectrum-textfield-width));
}

:host([multiline]) {
    resize: both;
}

:host([multiline][readonly]) {
    resize: none;
}

:host([disabled]:focus-visible) {
    outline: none;
}

#textfield {
    inline-size: 100%;
}

#textfield,
textarea {
    resize: inherit;
}

.input {
    min-inline-size: var(--spectrum-textfield-min-width);
}

:host([focused]) .input {
    caret-color: var(--swc-test-caret-color);
    forced-color-adjust: var(--swc-test-forced-color-adjust);
}

:host([focused]) #textfield:hover .input,
:host([focused]) .input:hover {
    border-color: var(--mod-textfield-border-color-focus-hover, var(--spectrum-textfield-border-color-focus-hover));
}

#sizer {
    block-size: auto;
    overflow-wrap: break-word;
    opacity: 0;
    white-space: pre-line;
}

.icon,
.icon-workflow {
    pointer-events: none;
}

:host([multiline]) #textfield {
    display: inline-grid;

    --spectrum-textfield-input-line-height: normal;
}

:host([multiline]) textarea {
    transition:
        box-shadow var(--spectrum-animation-duration-100, 0.13s) ease-in-out,
        border-color var(--spectrum-animation-duration-100, 0.13s) ease-in-out;
}

:host([multiline]:not([quiet])) #textfield:after {
    box-shadow: none;
}

:host([multiline][rows]) .input {
    block-size: auto;
    resize: none;
}

:host([multiline][rows="1"]) .input {
    min-block-size: auto;
}

/* restore specificity from the original Spectrum CSS */

:host([disabled][quiet]) #textfield .input,
:host([disabled][quiet]) #textfield:hover .input,
:host([quiet]) .input :disabled {
    background-color: #0000;
    border-color: var(--mod-textfield-border-color-disabled, var(--spectrum-textfield-border-color-disabled));
    color: var(--highcontrast-textfield-text-color-disabled, var(--mod-textfield-text-color-disabled, var(--spectrum-textfield-text-color-disabled)));
}

/* :not selector not working with regex for process-spectrum so had to override here */
:host([disabled]) #textfield .icon.icon-search,
:host([readonly]) #textfield .icon.icon-search {
    color: var(--highcontrast-textfield-text-color-disabled, var(--mod-textfield-text-color-disabled, var(--spectrum-textfield-text-color-disabled)));
}

:host([focused]) #textfield .icon.icon-search {
    --spectrum-search-color: var(--highcontrast-search-color-focus, var(--mod-search-color-focus, var(--spectrum-search-color-focus)));
}

:host([multiline][grows]:not([quiet])) #textfield:after {
    grid-area: unset;
    min-block-size: calc(var(--mod-text-area-min-block-size, var(--spectrum-text-area-min-block-size)) + var(--mod-textfield-focus-indicator-gap, var(--spectrum-textfield-focus-indicator-gap)) * 2);
}

:host([multiline][grows]:not([rows])) .input:not(#sizer) {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    resize: none;
    overflow: hidden;
}
